﻿@model MessageDesignModel
@using Nop.Plugin.Misc.MessageDesigner.Models;
@using Nop.Services.Events;
@using Nop.Core.Infrastructure;
@using Nop.Web.Framework;
@using Nop.Web.Framework.Events;
@using Nop.Web.Framework.UI;

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

<div id="design-edit">
    <ul>
        <li @Html.RenderSelectedTabIndex(0, GetSelectedTabIndex())>
            @T("Plugins.Misc.MessageDesigner.Info")
        </li>
        <li @Html.RenderSelectedTabIndex(1, GetSelectedTabIndex())>
            @T("Plugins.Misc.MessageDesigner.Stores")
        </li>
        <li @Html.RenderSelectedTabIndex(2, GetSelectedTabIndex())>
            @T("Plugins.Misc.MessageDesigner.NopMessageTemplates")
        </li>
    </ul>
    <div>
        @TabInfo()
    </div>
    <div>
        @TabStores()
    </div>
    <div>
        @TabNopMessageTemplates()
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#design-edit").kendoTabStrip({
            animation: {
                open: {
                    effects: "fadeIn"
                }
            },
            select: tabstrip_on_tab_select
        });
    });
</script>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "design-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab index*@
<input type="hidden" id="selected-tab-index" name="selected-tab-index" value="@(GetSelectedTabIndex())">

    <script>
        $(document).ready(function () {
            var htmlLine = "<div id=\"messageDesignerId\">\nDO NOT DELETE OR EDIT THIS DIV\nNOP CONTENT WILL BE PLACED HERE\n</div>";
            $("#codeToCopy").val(htmlLine);
        });
    </script>

@helper TabInfo()
{
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Name):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </td>
            <td rowspan="2">
                @if (Model.IsCreate)
                {
                    @T("Plugins.Misc.MessageDesigner.Instructions")
                }
                else
                {
                    @T("Plugins.Misc.MessageDesigner.InstructionsEdit")
                }
                <br />
                <textarea rows="7" cols="60" id="codeToCopy" disabled></textarea>
            </td>


        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AdminComment):
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.AdminComment, new { style = "Width: 250px; Height: 150px;" })
                @Html.ValidationMessageFor(model => model.AdminComment)
            </td>
        </tr>
    </table>
    @(Html.LocalizedEditor<MessageDesignModel, MessageDesignLocalizedModel>("messagetemplate-localized",
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].Body):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Locales[item].Body, "RichEditor")
                @Html.ValidationMessageFor(model => model.Locales[item].Body)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Html.HiddenFor(model => model.Locales[item].LanguageId)
            </td>
        </tr>
    </table>
    ,
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Body):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Body, "RichEditor")
                @Html.ValidationMessageFor(model => model.Body)
            </td>
        </tr>
    </table>
                                                                ))

}

@helper TabStores()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToStores)").click(toggleStoreMapping);

            toggleStoreMapping();
        });


        function toggleStoreMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToStores)').is(':checked')) {
                $('#pnl-available-stores').show();
            }
            else {
                $('#pnl-available-stores').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitedToStores):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToStores)
                @Html.ValidationMessageFor(model => model.LimitedToStores)
            </td>
        </tr>
        <tr id="pnl-available-stores">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AvailableStores):
            </td>
            <td class="adminData">
                @if (Model.AvailableStores != null && Model.AvailableStores.Count > 0)
                {
                    foreach (var store in Model.AvailableStores)
                    {
                        <div>
                            <input type="checkbox" name="SelectedStoreIds" value="@store.Id" checked="@(Model.SelectedStoreIds != null && Model.SelectedStoreIds.Contains(store.Id))" />@store.Name
                        </div>
                    }
                }
                else
                {
                    <div>No stores defined</div>
                }
            </td>
        </tr>
    </table>
}

@helper TabNopMessageTemplates()
{
    if (Model.Id > 0)
    {
        @Html.Action("TemplatesList", new { designId = Model.messageTemplateListLocalModel.MessageDesignId })
        @*@Html.Partial("~/Plugins/Misc.MessageDesigner/Views/TemplatesList.cshtml", Model.messageTemplateListLocalModel)*@
    }
    else
    {
        @T("plugins.misc.messagedesigner.SaveBeforeEdit")
    }

}

